package servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * servlet
 *
 * 使用SerlvetConfig对象实现信息共享
 *
 * M:首先调用ServletContextDemo1，往ServletContext对象中塞值。
 *   再调用ServletContextDemo2，获取ServletContextDemo1塞的值
 * 2018/5/13-9:34
 * 2018
 * Created by wuqiang on 2018/5/13.
 */
public class ServletContextDemo1 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //获取Context对象，并写值
        getServletContext().setAttribute("data","Result 决定 过程");
        //获取web.xml文件中，初始化的对象
        String initValue = (String) getServletContext().getInitParameter("initValue");
        System.out.println(initValue);
        resp.getOutputStream().write("write 完成！".getBytes());
    }


}
